<template>
	<el-dialog title="考勤导出对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="考勤规则" prop="configId">
				<el-select v-model="form.configId" filterable style="width: 100%" placeholder="考勤规则">
					<el-option v-for="item in attend" :key="item.configId" :label="item.title" :value="item.configId"/>
				</el-select>
			</el-form-item>
			<el-form-item label="导出部门" prop="deptId">
				<select-dept-dialog v-model:deptId="form.deptId" :mode="true"/>
			</el-form-item>
			<el-form-item label="导出人员" prop="createUser">
				<select-user-dialog v-model:accountId="form.createUser" :mode="false"/>
			</el-form-item>
			<el-form-item label="导出时间" prop="beginTime">
				<el-date-picker v-model="form.beginTime" placeholder="导出时间" type="month" value-format="YYYY-MM" style="width: 100%;"></el-date-picker>
			</el-form-item>
			<el-form-item label="考勤状态" prop="type">
				<el-select v-model="form.type" filterable style="width: 100%" placeholder="考勤状态">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
				</el-select>
			</el-form-item>
		</el-form>
		<div style="text-align: center;">
			<el-button type="success" icon="el-icon-download" @click="getExpAttendRecord">详情</el-button>
			<el-button type="success" icon="el-icon-download" @click="getExpAttendRecord2">汇总</el-button>
		</div>
	</el-dialog>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import selectDeptDialog from "@/views/module/selectDeptDialog";
	export default {
		components: {
			selectUserDialog,
			selectDeptDialog
		},
		emits: ['success', 'closed'],
		data() {
			return {
				visible: false,
				isSaveing: false,
				//表单数据
				attend:[],
				options: [{
					value: '',
					label: '全部'
				}, {
					value: '0',
					label: '正常'
				}, {
					value: '1',
					label: '迟到'
				}, {
					value: '2',
					label: '早退'
				}],
				form: {
					configId:"",
					deptId:"",
					createUser:"",
					beginTime:'',
					type:""
				},
				//验证规则
				rules: {
				},
			}
		},
		mounted() {
			this.getAttendConfig();
			this.getMonth();
		},
		methods: {
			//显示
			open(){
				this.visible = true;
				return this
			},
			async getAttendConfig(){
				var res = await this.$API.system.attendConfig.getAllAttendConfigList.get();
				if(res.code==200)
				{
					this.attend = res.data;
					this.form.configId = this.attend[0].configId;
				}
			},
			getMonth(){
				var data = new Date()
				var year = data.getFullYear();
				var month = data.getMonth();
				if(month<9)
				{
					this.form.beginTime = year + '-0' + (month + 1)
				}else
				{
					this.form.beginTime = year + '-' + (month + 1)
				}
			},
			getExpAttendRecord()
			{
				this.$confirm(`是否确认导出考勤明细吗？`, '提示', {
					type: 'warning'
				}).then(async() => {
					this.$API.office.attend.getExpAttendRecord.fileDownload(this.form);
				}).catch(() => {
				})
			},
			getExpAttendRecord2()
			{
				this.$confirm(`是否确认导出考勤汇总吗？`, '提示', {
					type: 'warning'
				}).then(async() => {
					this.$API.office.attend.getExpAttendRecord2.fileDownload(this.form);
				}).catch(() => {
				})
			},
		}
	}
</script>

<style>
</style>
